<template>
	<view class="content">
		<view class="title">
			欢迎登录农业平台
		</view>
		<view class="account">
			<view class="text">账号</view>
			<input v-model="phone" type="number" value="" placeholder="请输入手机号" />
		</view>
		<view class="code">
			<view class="text">验证码</view>
			<view class="bottom">
				<input v-model="code" type="number" value="" placeholder="请输入验证码" />
				<button @click="sendCode" :disabled="disable" :class="{get1:disable}" class="get" plain="true" type="default">{{seconds < 60 ? seconds+'后重新获取验证码' : '获取验证码'}}</button>
			</view>
		</view>
		<view class="account">
			<view class="text">新密码</view>
			<input v-model="password" type="password" value="" placeholder="请输入密码" />
		</view>
		<button @click="submitPassword" class="btn" type="default" :disabled="is_btn">修改密码</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				is_btn: false,
				phone: '',
				code: '',
				password: '',
				disable: false,
				seconds: 60
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: options.title
			})
		},
		methods: {
			//获取验证码
			sendCode(){
				let that = this;
				if(!(/^1[3456789]\d{9}$/.test(this.phone.trim()))){
					this.$u.toast('请输入正确的手机号');
					return
				}
				this.$http.post('/api/sms/send',{
					mobile: this.phone,
					event: 'resetpwd'
				}).then(res => {
					// console.log(res)
					this.$u.toast('验证码已发送');
					let interval = setInterval(() => {
						--that.seconds
					}, 1000)
					this.disable = true
					setTimeout(() => {
						clearInterval(interval)
						that.disable = false
						that.seconds = 60
					}, 60000)
				})
			},
			submitPassword(){
				if(!(/^1[3456789]\d{9}$/.test(this.phone.trim()))){
					this.$u.toast('请输入正确的手机号');
					return
				}
				if(this.code == ''){
					this.$u.toast('请输入验证码');
					return
				}
				if(this.password == ''){
					this.$u.toast('请输入密码');
					return
				}
				this.$http.post('/api/user/resetpwd',{
					mobile: this.phone,
					newpassword: this.password,
					captcha: this.code
				}).then(res => {
					// console.log(res)
					uni.navigateBack({
						delta: 1
					});
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content{
		width: 535rpx;
		margin: 0 auto;
		padding-bottom: 50rpx;
	}
	.title{
		font-size:28px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(51,51,51,1);
		margin-top: 124rpx;
		margin-bottom: 24rpx;
	}
	.account{
		margin-top: 82rpx;
		.text{
			font-size:20px;
			font-family:PingFang SC;
			font-weight:800;
			color:rgba(51,51,51,1);
		}
		input{
			border: none;
			outline: none;
			border-bottom: 1px solid #999999;
			display: block;
			width: 100%;
			height: 70rpx;
			margin-top: 30rpx;
			padding-bottom: 30rpx;
			box-sizing: border-box;
			min-height: none;
		}
	}
	.code{
		margin-top: 82rpx;
		.text{
			font-size:20px;
			font-family:PingFang SC;
			font-weight:800;
			color:rgba(51,51,51,1);
		}
		.bottom{
			margin-top: 30rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			border-bottom: 1px solid #999999;
			padding-bottom: 30rpx;
			box-sizing: border-box;
			input{
				border: none;
				outline: none;
				display: block;
				flex: 1;
			}
			.get{
				border: none;
				font-size:12px;
				font-family:PingFang SC;
				font-weight:500;
				color:rgba(63,195,119,1);
			}
			.get1 {
				color: #999999;
				border: 1upx solid #D2D2D2;
				border-radius: 1upx solid #D2D2D2;
			}
		}
	}
	
	.btn{
		margin-top: 53rpx;
		width:535rpx;
		height:88rpx;
		background:rgba(63,195,119,1);
		border-radius:10px;
		color:rgba(255,255,255,1);
	}
</style>
